{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Example: Static forward free-boundary equilibrium calculations (in EAST)\n", "\n", "---\n", "\n", "Here we will generate an equilibrium (solve for the plasma flux with fixed coil currents) on EAST using the machine geometry from [\"PF-Feedforward-EAST: physics-informed imitation learning for feedforward coil-current trajectory design on EAST\"](https://github.com/TokFusionAI/PF_Feedforward_EAST).\n", "\n", "The coil currents and equilibrium/profile parameters are based approximately on EAST shot 156715 at 5.109 s. Every finite-area active winding pack is represented by a uniform filament grid with a maximum spacing of approximately 3 cm; its original total ampere-turns and circuit wiring are preserved.\n", "\n", "Note that the machine description does not include a vacuum vessel!" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "### Import packages" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "### Create the machine object" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "# build machine\n", "from freegsnke import build_machine\n", "\n", "tokamak = build_machine.tokamak(\n", " active_coils_path=f\"../machine_configs/EAST/EAST_active_coils.pickle\",\n", " limiter_path=f\"../machine_configs/EAST/EAST_limiter.pickle\",\n", " wall_path=f\"../machine_configs/EAST/EAST_wall.pickle\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "# plot the machine\n", "fig, ax = plt.subplots(figsize=(8, 8), dpi=80)\n", "\n", "tokamak.plot(axis=ax, show=False) # plots the active coils\n", "ax.plot(tokamak.limiter.R, tokamak.limiter.Z, \"k-\", linewidth=1.2) # plots the limiter\n", "ax.grid(alpha=0.5)\n", "ax.set_aspect(\"equal\")\n", "ax.set_xlim(0.45, 3.45)\n", "ax.set_ylim(-2.2, 2.2)\n", "ax.set_xlabel(r\"Major radius, $R$ [m]\")\n", "ax.set_ylabel(r\"Height, $Z$ [m]\")" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "### Instantiate an equilibrium" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "from freegsnke import equilibrium_update\n", "\n", "eq = equilibrium_update.Equilibrium(\n", " tokamak=tokamak, # provide tokamak object\n", " Rmin=1.2, Rmax=2.5, # radial range\n", " Zmin=-1.3, Zmax=1.3, # vertical range\n", " nx=129, # number of radial grid points (needs to be of the form 2**n + 1)\n", " ny=129, # number of vertical grid points (needs to be of the form 2**n + 1)\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "# initialise the profiles\n", "from freegsnke.jtor_update import GeneralPprimeFFprime\n", "\n", "# EFIT profiles from EAST shot 156715 at 5.109 s\n", "psi_n = np.linspace(0.0, 1.0, 129)\n", "pprime_data = 778923.7959794602 * (psi_n - 1.0)\n", "ffprime_data = (\n", " 1.0163643105813263 * psi_n**2\n", " - 1.9553728814507954 * psi_n\n", " + 0.9390085708694674\n", ")\n", "\n", "profiles = GeneralPprimeFFprime(\n", " eq=eq, # equilibrium object\n", " Ip=448349.0, # plasma current [A]\n", " fvac=4.6103095348117815, # fvac = R * B_tor [T m]\n", " psi_n=psi_n, # normalised poloidal flux\n", " pprime_data=pprime_data, # pressure derivative profile\n", " ffprime_data=ffprime_data, # FF' profile\n", " Raxis=1.9012964048754795, # magnetic-axis radius [m]\n", " Ip_logic=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# set the coil currents\n", "# note that PF7 supplies the PF7/PF9 circuit and PF8 supplies the PF8/PF10 circuit\n", "coil_currents = {\n", " \"PF1\": 1359.09375,\n", " \"PF2\": 1551.1722412109375,\n", " \"PF3\": 6525.3671875,\n", " \"PF4\": 1948.96630859375,\n", " \"PF5\": -4642.3076171875,\n", " \"PF6\": 1589.8978271484375,\n", " \"PF7\": 9013.955078125,\n", " \"PF8\": 8778.06640625,\n", " \"PF11\": -9200.0, # modified from source value to move the plasma away from the outboard wall\n", " \"PF12\": -9590.9765625,\n", " \"PF13\": 1279.05419921875,\n", " \"PF14\": 1260.845703125,\n", " \"IC1\": 0.0,\n", " \"IC2\": 0.0,\n", "}\n", "\n", "\n", "eq.tokamak.set_all_coil_currents(\n", " np.array([coil_currents[name] for name, _ in tokamak.coils])\n", ")" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "### The forward solve" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "# load the static nonlinear solver\n", "from freegsnke import GSstaticsolver\n", "from freegsnke.equilibrium import PsiGuessParabolicJtor\n", "\n", "GSStaticSolver = GSstaticsolver.NKGSsolver(eq, seed=42)\n", "\n", "\n", "# adjust the initial guess to reduce the number of solver iterations\n", "psi_guess = PsiGuessParabolicJtor(\n", " h = (min(tokamak.limiter.R)+max(tokamak.limiter.R))/2, # radial centre of ellipse\n", " k = 0.0, # vertical centre of ellipse\n", " a = 0.5, # approximate radial minor radius of the plasma\n", " b = 0.5 * 1.8, # approximate vertical minor radius of the plasma\n", " Ip = profiles.Ip, # plasma current used to scale the guess\n", " psi_scale = 1.0 # scaling factor for the initial flux guess\n", ")\n", "\n", "# calculate the initial plasma flux\n", "plasma_psi = psi_guess.__call__(\n", " eq=eq,\n", ")\n", "\n", "eq.plasma_psi = plasma_psi\n", "# carry out the forward solve with fixed coil currents\n", "GSStaticSolver.forward_solve(\n", " eq=eq,\n", " profiles=profiles,\n", " target_relative_tolerance=1e-7,\n", " max_solving_iterations=75,\n", " verbose=True, # print output\n", ")" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "### Plot the equilibrium" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(8, 8), dpi=80)\n", "\n", "ax.grid(zorder=0, alpha=0.75)\n", "ax.set_aspect(\"equal\")\n", "eq.tokamak.plot(axis=ax, show=False) # plots the active coils\n", "eq.plot(axis=ax, show=False) # plots the equilibrium\n", "ax.plot(tokamak.limiter.R, tokamak.limiter.Z, \"k-\", linewidth=1.2) # plots the limiter\n", "ax.set_xlabel(r\"Major radius, $R$ [m]\")\n", "ax.set_ylabel(r\"Height, $Z$ [m]\")" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "freegsnke", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.20" } }, "nbformat": 4, "nbformat_minor": 4 }